using Aurora.SingalR.Hubs;
using Aurora.TaskScheduler.Abstractions;
using Aurora.TaskScheduler.Abstractions.BaseModel;
using Gateway.IApplication.Order;

namespace Gateway.UI.Api.TaskJobs;

/// <summary>
/// 
/// </summary>
public class TestBackgroundJob : ITaskJob<HubMessage>
{
    private readonly IOrderApp _orderApp;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="orderApp"></param>
    public TestBackgroundJob(IOrderApp orderApp)
    {
        _orderApp = orderApp;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="parameter"></param>
    /// <returns></returns>
    public async Task<JobResult> ExecuteAsync(HubMessage parameter)
    {
        Console.WriteLine("TestBackgroundJob 开始执行了");
        Console.WriteLine("参数：" + parameter);
        int count = 500;
        for (int i = 0; i < count; i++)
        {
            var orderTime = DateTime.Now;
            var orderId = await _orderApp.Add(orderTime);
            Console.WriteLine($"order id:{orderId}");
        }

        Console.WriteLine("TestBackgroundJob 执行结束");
        return JobResult.CreateSuccess();
    }
}